<template>
<div>
  <el-dialog
      title="welcome"
      :visible.sync="dialogVisible"
      :show-close="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      width="60%">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="账号">
        <el-input v-model="form.uid"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>
</div>
</template>

<script>


import {login} from "@/api/app";

export default {
  name: 'LoginView',
  data(){
    return {
      dialogVisible:true,
      form:{
        uid:'',
        password:'',
        usertype:'1'
      }
    }
  },
  methods:{
    onSubmit(){
      login(this.form).then(res=>{
        console.log(res)
        if(res.code==200){
          console.log(res.data.user.role)
          this.$router.push({ path: '/books', query: { uid: this.form.uid ,role:res.data.user.role} });
        }else if(res.code==300){
          this.$message.error(res.msg)
        }
      })
    }
  }

}
</script>
